caijiMgr = {}
QMPlugin = caijiMgr
function caijiMgr.init(maxCount)
    caijiMgr.maxCount = maxCount or 999
    caijiMgr.curCount = 0
    caijiMgr.curLine = 1
    caijiMgr.paraConfig = {
        ["狩猎按钮"] = { 365,1295,505,1423,"A08B74","28|-27|73705C,16|-21|5A5543,7|-18|897920,-3|-31|EAE0D6,8|-6|CBC5BC,-6|-12|A79181,-15|-14|F0DBCC,-26|-6|F6E2CB,-49|-2|E8F1F4",0,0.9},
        ["狩猎工具不够按钮"] = { 350,1284,524,1446,"436466","-23|-12|1B3853,-45|-13|22433A,-54|10|1C3731,-38|37|152A50,-64|-17|5B5E60,-75|-1|515659,-72|26|43484D",0,0.9},
        ["加号购买按钮"] = { 44,1424,496,1547,"C7EDFB","-2|-19|C2E6F2,0|15|C7ECFB,15|0|D2F2FF,-17|-1|BFE9F7,-2|-33|3B5352,-3|30|3B5352,28|-3|3B5352,-35|-3|3B5352",0,0.9},
        ["购买按钮"] = { 41,1438,137,1755,"4D56D8","29|-3|6268EB,-2|129|4C54D6,-26|-8|5560E6,4|-136|4F58D9,15|-27|CEECFE,-6|-16|C3E0FB,19|29|CFEDFE,-5|21|C7E4FC,-7|36|CDEBFD",0,0.9},
        ["商城关闭按钮"] = {967,1765,1078,1912,"88CEFC","20|-19|71B5F9,1|-37|394079,-18|-18|9EE5FE,-42|-3|444484,-23|21|A2EAFF,3|33|3B407F,19|20|72B7FA,36|1|343F79",0,0.9},
    }
end

-- 查看身上是否有狩猎按钮
local function checkShoulieBtn()
    local para = caijiMgr.paraConfig["狩猎按钮"]
    local itemX,itemY = game.findMultiColor(utils.unpack(para))
    if itemX == -1 or itemY == - 1 then
        return false,itemX,itemY
    else
        return true,itemX,itemY
    end
end

-- 查看身上是否有狩猎工具不够按钮
local function checkShoulieNotEnoughBtn()
    local para = caijiMgr.paraConfig["狩猎工具不够按钮"]
    local itemX,itemY = game.findMultiColor(utils.unpack(para))
    if itemX == -1 or itemY == - 1 then
        return false,itemX,itemY
    else
        return true,itemX,itemY
    end
end

function caijiMgr.execTask()
    LuaAuxLib.TracePrint("狩猎开始 execTask")
    while caijiMgr.curCount < caijiMgr.maxCount do
        accidentEvent.check()
        local btnShow,x,y = checkShoulieBtn()
        if btnShow then
            LuaAuxLib.TracePrint("点击狩猎按钮当前数量：", caijiMgr.curCount)
            caijiMgr.curCount = caijiMgr.curCount + 1
            game.tap(x, y)
            game.delay(3500)
        else
            btnShow,x,y = checkShoulieNotEnoughBtn()
            if btnShow then
                mlog.info("狩猎工具不够按钮")
                game.tap(x, y)
                game.delay(500)
                local para = caijiMgr.paraConfig["加号购买按钮"]
                local itemX,itemY = game.findMultiColor(utils.unpack(para))
                if itemX > -1 and itemY > -1 then
                    mlog.info("点击加号按钮")
                    game.tap(itemX, itemY)
                    game.delay(800)
                    para = caijiMgr.paraConfig["购买按钮"]
                    itemX,itemY = game.findMultiColor(utils.unpack(para))
                    if itemX > -1 and itemY > -1 then
                        mlog.info("点击购买按钮")
                        game.tap(itemX, itemY)
                        game.delay(300)

                        para = caijiMgr.paraConfig["商城关闭按钮"]
                        itemX,itemY = game.findMultiColor(utils.unpack(para))
                        if itemX > -1 and itemY > -1 then
                            mlog.info("商城关闭按钮")
                            game.tap(itemX, itemY)
                        end
                    end
                else
                    game.delay(2000)
                end
            end
            game.delay(500)
        end
        game.switchLine()
        game.delay(1000)
    end
    LuaAuxLib.TracePrint("已完成狩猎数量：", caijiMgr.curCount)
end